//
//  BusSaleTicketTimeCell.swift
//  SwiftTestDemo
//
//  Created by John on 2018/5/22.
//  Copyright © 2018年 company. All rights reserved.
//

import UIKit

class BusSaleTicketTimeCell: UITableViewCell {
    
    @IBOutlet weak var vFilletBackView: UIView!
    @IBOutlet weak var lblSalesTicketTime: UILabel!
    
    var _sSalesTicketTime:String?{
        didSet{
            self.lblSalesTicketTime.attributedText = self.attributedStringWithString(sSalesTickerTime: sSalesTicketTime!)
        }
    }
    
    var sSalesTicketTime:String?{
        get{
            return _sSalesTicketTime
        }
        set{
            _sSalesTicketTime = newValue
        }
        
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.backgroundColor = color_Backgroud
        self.lblSalesTicketTime.textColor = def_color_Secondary
        self.vFilletBackView.layer.masksToBounds = true
        self.vFilletBackView.layer.cornerRadius = 4;
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    //将预计售票文字渲染成富文本（加颜色）
    func attributedStringWithString(sSalesTickerTime:String) -> NSMutableAttributedString? {
        
        //转换时间格式
        let sDate:NSString? = TCDateFormatter.stringToStringCustom(self.sSalesTicketTime!, TCDateFormatter.def_YearMonthDayHourMinuteSec_DF, TCDateFormatter.def_MonthDayChn_DF)! as NSString
        
        let sMix:NSString = "车站预计\(sDate!)售票，开售后优先为您出票" as NSString
        
        //编辑可变字符
        let att:NSMutableAttributedString? = NSMutableAttributedString.init(string: sMix as String)
        
        //改变颜色
        att?.addAttribute(NSAttributedStringKey.foregroundColor, value: customBlueColor, range: sMix.range(of: sDate! as String))
        
        return att
        
    }
    
}
